package com.voute.Presenter.Impl;

import com.voute.Model.Bean.BaseBean;
import com.voute.Model.IPostCommentModel;
import com.voute.Model.IUxTagModel;
import com.voute.Model.Impl.PostCommentModelImpl;
import com.voute.Model.Impl.UXTagModelImpl;
import com.voute.Presenter.IPostCommentPresenter;
import com.voute.Utils.CommonSubscriber;
import com.voute.Utils.PreferenceUtils;
import com.voute.Utils.TransformUtils;
import com.voute.View.IView.IPostCommentView;

import java.util.HashMap;

import rx.functions.Action0;

/**
 * Created by liucxu on 2017/1/25.
 */

public class PostCommentPresenterImpl implements IPostCommentPresenter {

    private IPostCommentView post_view;
    private IPostCommentModel model;
    private IUxTagModel uxModel;

    public PostCommentPresenterImpl(IPostCommentView view) {
        post_view = view;
        model = new PostCommentModelImpl();
        uxModel = new UXTagModelImpl();
    }


    @Override
    public void postComment(final String fid, final String content, final String side, final String pic) {
        HashMap<String,String> params=new HashMap<>();
        params.put("content",content);
        params.put("lat", PreferenceUtils.GetLatitude());
        params.put("lng", PreferenceUtils.GetLongtitude());
        model.postComment(fid,params).compose(TransformUtils.<BaseBean>defaultSchedulers()).doOnSubscribe(new Action0() {
            @Override
            public void call() {
                post_view.showLoading();
            }
        }).subscribe(new CommonSubscriber<BaseBean>() {
            @Override
            public void onSuccess(BaseBean response) {
                post_view.hideLoading();
                post_view.postCommentSuccess(response);
            }

            @Override
            public void onFailure(BaseBean response) {
                post_view.hideLoading();
                post_view.showError(response.getMsg());
            }
        });
    }
}
